//
// Created by Administrator on 2025/7/27.
//

#ifndef ACL_YOLOV8_BASICCLIENT_H
#define ACL_YOLOV8_BASICCLIENT_H
#include <iostream>
#include "acl/acl.h"
#include <string>
#include <vector>
#include <algorithm>
#include <chrono>
using namespace std;
#define RGBU8_IMAGE_SIZE(width, height) ((width) * (height) * 3)
#define RGBAU8_IMAGE_SIZE(width, height) ((width) * (height) * 4)

typedef enum  {
    SUCCESS = 0,
    FAILED = 1
}Result;

typedef enum{
    RGB = 1,
    GRAY = 2,
}INPUT_TYPE;



typedef struct  {
    float x;
    float y;
    float w;
    float h;
    float score;
    int classIndex;
    int index; // index of output buffer
} BBox;

typedef struct tag_ImgMat
{
    /* data */
    unsigned char* data = nullptr;
    // bool relayout=false;
}ImgMat;

class BasicClient {
private:
    /* data */
    uint32_t g_modelId_;
    int32_t g_deviceId_;  // Device ID, default is 0


    aclmdlDesc *g_modelDesc_;
    aclrtContext g_context_;
    aclrtStream g_stream_;
    aclmdlDataset *g_input_;
    aclmdlDataset *g_output_;



    const char* omModelPath;

public:
    BasicClient(const char* modelPath, uint32_t modelWidth, uint32_t modelHeight);
    ~BasicClient();

    void*  g_imageDataBuf_;      // Model input data cache
    uint32_t g_imageDataSize_; // Model input data size
    aclrtRunMode g_runMode_;


public:
    Result Init_atlas();
    Result CreateInput();
    Result CreateOutput();
    Result inference();
    void* GetInferenceOutputItem(uint32_t& itemDataSize, uint32_t idx);
    void* CopyDataDeviceToLocal(void* deviceData, uint32_t dataSize);


    void DestroyResource();
    void DestroyDesc();
    void DestroyInput();
    void DestroyOutput();
};


#endif //ACL_YOLOV8_BASICCLIENT_H
